<?php
/**
 * CheckRangeSchedulePerWorker function
 *
 * Return schedule for specified date range for specified employee
 *
 * @author Will Zhao <kexinzhao666@gmail.com>
 */
include_once 'UTDBGlobal.php';
include_once 'UTerrorcode.php';
include_once 'UTcheckAuth.php';

function checkRangeSchedulePerWorker($userName, $userPassHash, $startDate, $endDate,$empID)
{
    global $dbaddress;
    global $dbuser;
    global $dbpassword;
    global $dbdatabasename;
 $err=new ErrorCode();
 $array=array();
	if(checkAuthentication($userName,$userPassHash))
	{
		$conn = mysqli_connect($dbaddress,$dbuser,$dbpassword,$dbdatabasename);
                $sql= "select account.accName,roles.roleName,
roles.roleID,roledate.dateID,roledate.startTime,
roledate.endTime,roledate.shiftStatus,dates.datestamp from  
employees left join (dates,roledate,account,roles) on          
roledate.empID=employees.empID and dates.dateID=roledate.dateID and
account.empID=employees.empID and roles.roleID=roledate.roleID 
where dates.datestamp between '".$sDate."' and '".$eDate."' and employees.empID=".$empID;
		$result=$conn->query($sql);
		if ($result)
		{
			 if($result->num_rows>0)
			 {
			    		while($row=$result->fetch_array())
						{
						$array[] = array(
								'roleName'=>$row['roleName'],
								'roleID'=>$row['roleID'],
								'dateID'=>$row['dateID'],
								'roleName'=>$row['roleName'],
								'date'=>$row['datestamp'],
								'startTime'=>$row['startTime'],
								'startTime'=>$row['endTime'],
								'shiftStatus'=>$row['shiftStatus']);
						}
						$error=$err::successRead;    
			 }  
		}
		else
		{
		      $error =$err::failRead;
		}
	}
	else
	{
		$error =$err::authFailRead;
	}
        array_unshift($array,$error);
				$result->free();
				$conn->close();
        return $array;
}
?>